#ifndef LOGWRITER_H
#define LOGWRITER_H

#include<QThread>
#include"blockqueue.h"
#include<QFile>
#include<QString>
#include<QDir>
class LogWriter: public QThread
{
    Q_OBJECT
public:
    LogWriter(const QString&logPath,QObject*parent);
    ~LogWriter();

    void stop();


    void processRemainingLogs();

    //提供一个往queue写入数据的接口
    void writeQueue(const LogMessage&msg);


protected:
    void run();

private:

    BlockQueue*m_queue;
    QFile m_logFile;
    QString m_logPath;
    bool m_running;
    QTextStream m_logStream;   // 文件输出流

    bool checkAndCreateLogFile();
    QString formatLogMessage(const LogMessage& msg);


signals:
    // 信号：发送格式化后的日志文本（传递到 UI 主线程）
    void logReadyForUI(const QString& fromattedLog);

};

#endif // LOGWRITER_H
